-- sla 100000
SELECT CASE 1
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 2
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 3
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 4
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 5
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 6
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 1
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_V1
GO

SELECT CASE 2
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_V1
GO

SELECT CASE 3
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_V1
GO

SELECT CASE 4
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_V1
GO

SELECT CASE 5
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_V1
GO

SELECT CASE 6
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
END AS RESULT FROM BABEL_5103_V1
GO

SELECT CASE 1
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 2
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 3
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 4
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 1
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
END AS RESULT FROM BABEL_5103_V1
GO

SELECT CASE 2
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
END AS RESULT FROM BABEL_5103_V1
GO

SELECT CASE 3
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
END AS RESULT FROM BABEL_5103_V1
GO

SELECT CASE 4
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
END AS RESULT FROM BABEL_5103_V1
GO

SELECT CASE 1
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 1
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
END AS RESULT FROM BABEL_5103_V1
GO

SELECT CASE 2
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
END AS RESULT FROM BABEL_5103_T1
GO

SELECT CASE 2
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
END AS RESULT FROM BABEL_5103_V1
GO

-- Function call
SELECT BABEL_5103_F1('REGULAR');
GO

SELECT BABEL_5103_F1(N'登録カード–標準');
GO

SELECT BABEL_5103_F1(N'بطاقة التسجيل - قياسية');
GO

-- selecting from view
SELECT * FROM BABEL_5103_V2
GO

-- single branch
SELECT CASE 1
   WHEN 1 THEN CAST('char' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char' AS NTEXT)
END AS RESULT
GO

-- single branch with multibyte character
SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

-- multiple branch without NULL one being NVARCHAR
SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

-- multiple branch without NULL one being VARCHAR
SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS VARCHAR(100))
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS VARCHAR(100))
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS VARCHAR(100))
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS VARCHAR(100))
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS VARCHAR(100))
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS VARCHAR(100))
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS VARCHAR(100))
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS VARCHAR(100))
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

-- multiple branch without NULL one being CHAR
SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS Char(100))
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS CHAR(100))
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS CHAR(100))
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS CHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS CHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS CHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS Char(100))
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS CHAR(100))
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS CHAR(100))
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS CHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS CHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS CHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

-- multiple branch without NULL one being NCHAR
SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NCHAR(100))
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NCHAR(100))
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS NCHAR(100))
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS NCHAR(100))
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

-- multiple branch without NULL one being TEXT
SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS TEXT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS TEXT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS TEXT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS TEXT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

-- multiple branch with one being string literal
SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS Char(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS CHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS TEXT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS Char(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS Char(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS Char(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS CHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS TEXT)
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS Char(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS CHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS TEXT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO


SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS Char(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS Char(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS Char(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS CHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS TEXT)
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS CHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS Char(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS CHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS TEXT)
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS CHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS Char(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS CHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS TEXT)
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS Char(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS CHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 3
   WHEN 1 THEN N'登録カード–標準'
   WHEN 2 THEN CAST('char0' AS TEXT)
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

-- multiple branches one being NULL
SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS Char(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS CHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS TEXT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO


SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS Char(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS Char(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

-- NULL tests
SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NVARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS Char(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS CHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST('char0' AS TEXT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS Char(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
   WHEN 3 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NVARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS Char(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN NULL
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
   WHEN 3 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

-- other datatypes then string 
SELECT CASE 1
   WHEN 1 THEN CAST(123 AS INT)
   WHEN 2 THEN CAST(456 AS DECIMAL(10, 2))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(123.456 AS FLOAT)
   WHEN 2 THEN CAST(789.123 AS NUMERIC(10, 3))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(123 AS SMALLINT)
   WHEN 2 THEN CAST(456789123 AS BIGINT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(123 AS SMALLINT)
   WHEN 2 THEN CAST(456 AS DECIMAL(10, 2))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(123.456 AS BIGINT)
   WHEN 2 THEN CAST(789.123 AS NUMERIC(10, 3))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(123 AS SMALLINT)
   WHEN 2 THEN CAST(456789123 AS BIGINT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('2024-01-01' AS DATE)
   WHEN 2 THEN CAST('2024-09-27 12:34:56' AS DATETIME)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('12:34:56' AS TIME)
   WHEN 2 THEN CAST('2024-09-27 12:34:56.1234567' AS DATETIME2(7))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1 AS BIT)
   WHEN 2 THEN CAST(0 AS BIT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BINARY(3))
   WHEN 2 THEN CAST(0xABCDEF AS VARBINARY(6))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1000.00 AS MONEY)
   WHEN 2 THEN CAST(100.00 AS SMALLMONEY)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(123 AS INT)
   WHEN 2 THEN CAST(456 AS DECIMAL(10, 2))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(123.456 AS FLOAT)
   WHEN 2 THEN CAST(789.123 AS NUMERIC(10, 3))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(123 AS SMALLINT)
   WHEN 2 THEN CAST(456789123 AS BIGINT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(123 AS SMALLINT)
   WHEN 2 THEN CAST(456 AS DECIMAL(10, 2))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(123.456 AS BIGINT)
   WHEN 2 THEN CAST(789.123 AS NUMERIC(10, 3))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(123 AS SMALLINT)
   WHEN 2 THEN CAST(456789123 AS BIGINT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('2024-01-01' AS DATE)
   WHEN 2 THEN CAST('2024-09-27 12:34:56' AS DATETIME)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('12:34:56' AS TIME)
   WHEN 2 THEN CAST('2024-09-27 12:34:56.1234567' AS DATETIME2(7))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(1 AS BIT)
   WHEN 2 THEN CAST(0 AS BIT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BINARY(3))
   WHEN 2 THEN CAST(0xABCDEF AS VARBINARY(6))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(1000.00 AS MONEY)
   WHEN 2 THEN CAST(100.00 AS SMALLMONEY)
END AS RESULT
GO

-- Collation tests
-- FIX ME: Following test cases shows behaviour mismatch,
-- When we compare N'  比尔·拉莫斯    ' COLLATE japanese_ci_as
-- with N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS  for CASE expression,
-- Gives 'true' (as used in PG), whereas it should give 'false' (as in TSQL).

SELECT CASE 'abcd' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  比尔·拉莫斯    ' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'بطاقة التسجيل - قياسية' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  abc🙂defghi🙂🙂    ' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE 'abcd' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'بطاقة التسجيل - قياسية' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE 'abcd' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  比尔·拉莫斯    ' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  abc🙂defghi🙂🙂    ' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE 'abcd' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN CAST('abcd' AS VARCHAR(100))
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  比尔·拉莫斯    ' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  比尔·拉莫斯    ' AS VARCHAR(100))
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'بطاقة التسجيل - قياسية' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  abc🙂defghi🙂🙂    ' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  abc🙂defghi🙂🙂    ' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 'abcd' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN CAST('abcd' AS VARCHAR(100))
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  比尔·拉莫斯    ' AS VARCHAR(100))
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'بطاقة التسجيل - قياسية' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  abc🙂defghi🙂🙂    ' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 'abcd' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN CAST('abcd' AS VARCHAR(100))
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  比尔·拉莫斯    ' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  比尔·拉莫斯    ' AS VARCHAR(100))
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  abc🙂defghi🙂🙂    ' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  abc🙂defghi🙂🙂    ' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 'abcd' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN CAST('abcd' AS VARCHAR(100))
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  比尔·拉莫斯    ' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  比尔·拉莫斯    ' AS VARCHAR(100))
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'بطاقة التسجيل - قياسية' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  abc🙂defghi🙂🙂    ' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  abc🙂defghi🙂🙂    ' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 'abcd' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN CAST('abcd' AS VARCHAR(100))
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  比尔·拉莫斯    ' AS VARCHAR(100))
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'بطاقة التسجيل - قياسية' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  abc🙂defghi🙂🙂    ' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 'abcd' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN CAST('abcd' AS VARCHAR(100))
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  比尔·拉莫斯    ' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  比尔·拉莫斯    ' AS VARCHAR(100))
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    '
END AS RESULT
GO

SELECT CASE N'  abc🙂defghi🙂🙂    ' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    '
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية'
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN CAST(N'  abc🙂defghi🙂🙂    ' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 'abcd' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd' COLLATE CHINESE_PRC_CI_AS
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية' COLLATE CHINESE_PRC_CI_AS
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS
END AS RESULT
GO

SELECT CASE N'  abc🙂defghi🙂🙂    ' COLLATE japanese_ci_as
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd' COLLATE japanese_ci_as
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    ' COLLATE japanese_ci_as
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية' COLLATE japanese_ci_as
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    ' COLLATE japanese_ci_as
END AS RESULT
GO

SELECT CASE 'abcd' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd'
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية' COLLATE CHINESE_PRC_CI_AS
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS
END AS RESULT
GO

SELECT CASE N'بطاقة التسجيل - قياسية' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd' COLLATE japanese_ci_as
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    ' COLLATE japanese_ci_as
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية' COLLATE japanese_ci_as
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    ' COLLATE japanese_ci_as
END AS RESULT
GO

SELECT CASE N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd' COLLATE ARABIC_CI_AS
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    ' COLLATE ARABIC_CI_AS
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    ' COLLATE ARABIC_CI_AS
END AS RESULT
GO

SELECT CASE 'abcd' COLLATE ARABIC_CI_AS
   WHEN 'abcd' COLLATE japanese_ci_as THEN 'abcd' COLLATE CHINESE_PRC_CI_AS
   WHEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS THEN N'  比尔·拉莫斯    ' COLLATE CHINESE_PRC_CI_AS
   WHEN N'بطاقة التسجيل - قياسية' COLLATE ARABIC_CI_AS THEN N'بطاقة التسجيل - قياسية' COLLATE CHINESE_PRC_CI_AS
   WHEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS THEN N'  abc🙂defghi🙂🙂    ' COLLATE CHINESE_PRC_CI_AS
END AS RESULT
GO

--- SYSNAME tests
SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN 'بطاقة التسجيل - قياسية'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN 'abc'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS sysname)
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN CAST('char' AS sysname)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS sysname)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS sysname)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS sysname)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS sysname)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS sysname)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS sysname)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS sysname)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS sysname)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS sysname)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS sysname)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS sysname)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS sysname)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS sysname)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS sysname)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS sysname)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS sysname)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS sysname)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS sysname)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS sysname)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS sysname)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS sysname)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS sysname)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS sysname)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS sysname)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS sysname)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS sysname)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS sysname)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS sysname)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS sysname)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS sysname)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS sysname)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS sysname)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS sysname)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS sysname)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

--- UDT testing
create type BABEL_CASE_EXPR_TEST_UDT from NVARCHAR(100);
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'بطاقة التسجيل - قياسية'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'abc'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT;
go

create type BABEL_CASE_EXPR_TEST_UDT from sysname;
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'بطاقة التسجيل - قياسية'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'abc'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT;
go


create type BABEL_CASE_EXPR_TEST_UDT from VARCHAR(100);
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'بطاقة التسجيل - قياسية'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'abc'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT;
go

create type BABEL_CASE_EXPR_TEST_UDT from CHAR(100);
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'بطاقة التسجيل - قياسية'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'abc'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT;
go

create type BABEL_CASE_EXPR_TEST_UDT from NCHAR(100);
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'بطاقة التسجيل - قياسية'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'abc'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT;
go

create type BABEL_CASE_EXPR_TEST_UDT from TEXT;
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'بطاقة التسجيل - قياسية'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'abc'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT;
go

create type BABEL_CASE_EXPR_TEST_UDT from NTEXT;
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'بطاقة التسجيل - قياسية'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'abc'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT;
go

-- multiple branch one being Binary
create type BABEL_CASE_EXPR_TEST_UDT from BINARY(100);
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(0x123456 AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 0x123456
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 0x123456
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 0x123456
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(0x123456 AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(0x123456 AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(0x123456 AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(0x123456 AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(0x123456 AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(0x123456 AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(0x123456 AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(0x123456 AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(0x123456 AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(0x123456 AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'بطاقة التسجيل - قياسية'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'abc'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO


SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT;
go

-- multiple branch one being VARBINARY
create type BABEL_CASE_EXPR_TEST_UDT from VARBINARY(100);
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'بطاقة التسجيل - قياسية'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'abc'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(0x123456 AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 3 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT;
go

-- multiple UDT branches
create type BABEL_CASE_EXPR_TEST_UDT0 from NVARCHAR(100);
GO

create type BABEL_CASE_EXPR_TEST_UDT1 from NCHAR(100);
GO

create type BABEL_CASE_EXPR_TEST_UDT2 from CHAR(100);
GO

create type BABEL_CASE_EXPR_TEST_UDT3 from VARCHAR(100);
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST(N'بطاقة التسجيل - قياسية' AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT3)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 2 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT3)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT2)
   WHEN 2 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT1)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 2 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT1)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT1)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 2 THEN CAST('char' AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT2)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT3)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT2)
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT0;
go

drop type BABEL_CASE_EXPR_TEST_UDT1;
go

drop type BABEL_CASE_EXPR_TEST_UDT2;
go

drop type BABEL_CASE_EXPR_TEST_UDT3;
go

-- Numeric datatypes
create type BABEL_CASE_EXPR_TEST_UDT0 from INT;
GO

create type BABEL_CASE_EXPR_TEST_UDT1 from DECIMAL;
GO

create type BABEL_CASE_EXPR_TEST_UDT2 from FLOAT;
GO

create type BABEL_CASE_EXPR_TEST_UDT3 from BIT;
GO

SELECT CASE 2
   WHEN 1 THEN CAST(123 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST(2.300 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(54132 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST(0 AS BABEL_CASE_EXPR_TEST_UDT3)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(12.3 AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 2 THEN CAST(3.456 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(324 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST(1 AS BABEL_CASE_EXPR_TEST_UDT3)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(5.34 AS BABEL_CASE_EXPR_TEST_UDT2)
   WHEN 2 THEN CAST(1.345 AS BABEL_CASE_EXPR_TEST_UDT1)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(1 AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 2 THEN CAST(1321 AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.24 AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 2 THEN CAST(0 AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 3 THEN CAST(1.234 AS BABEL_CASE_EXPR_TEST_UDT1)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.24 AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 2 THEN CAST(1235 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 3 THEN CAST(0.345 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.24 AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 2 THEN CAST(234.234 AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST(346 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.24 AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 2 THEN CAST(04545 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 3 THEN CAST(12.4 AS BABEL_CASE_EXPR_TEST_UDT1)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.24 AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 2 THEN CAST(1 AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 3 THEN CAST(234.234 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0 AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 2 THEN CAST(3.456 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 2 THEN CAST(123.3 AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST(546 AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

SELECT CASE 2
   WHEN 2 THEN CAST(54 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 3 THEN CAST(0.123 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 2 THEN CAST(23 AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST(6356 AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(234 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST(3456.34 AS BABEL_CASE_EXPR_TEST_UDT2)
   WHEN 3 THEN CAST(0 AS BABEL_CASE_EXPR_TEST_UDT3)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(345.345 AS BABEL_CASE_EXPR_TEST_UDT2)
   WHEN 2 THEN CAST(23.12 AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST(2354 AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT0;
go

drop type BABEL_CASE_EXPR_TEST_UDT1;
go

drop type BABEL_CASE_EXPR_TEST_UDT2;
go

drop type BABEL_CASE_EXPR_TEST_UDT3;
go

-- Mixture of numeric and string types
create type BABEL_CASE_EXPR_TEST_UDT0 from INT;
GO

create type BABEL_CASE_EXPR_TEST_UDT1 from NCHAR(100);
GO

create type BABEL_CASE_EXPR_TEST_UDT2 from FLOAT;
GO

create type BABEL_CASE_EXPR_TEST_UDT3 from VARCHAR(100);
GO

SELECT CASE 2
   WHEN 1 THEN CAST(123 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST(2.300 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(54132 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT3)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 2 THEN CAST(3.456 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(324 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT3)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(5.34 AS BABEL_CASE_EXPR_TEST_UDT2)
   WHEN 2 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT1)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 2 THEN CAST(1321 AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT1)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(1235 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 3 THEN CAST(0.345 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST(346 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(04545 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT1)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 3 THEN CAST(234.234 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT3)
   WHEN 2 THEN CAST(3.456 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST(546 AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(54 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 3 THEN CAST(0.123 AS BABEL_CASE_EXPR_TEST_UDT2)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST(6356 AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(234 AS BABEL_CASE_EXPR_TEST_UDT0)
   WHEN 2 THEN CAST(3456.34 AS BABEL_CASE_EXPR_TEST_UDT2)
   WHEN 3 THEN CAST('char1' AS BABEL_CASE_EXPR_TEST_UDT3)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(345.345 AS BABEL_CASE_EXPR_TEST_UDT2)
   WHEN 2 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT1)
   WHEN 3 THEN CAST(2354 AS BABEL_CASE_EXPR_TEST_UDT0)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT0;
go

drop type BABEL_CASE_EXPR_TEST_UDT1;
go

drop type BABEL_CASE_EXPR_TEST_UDT2;
go

drop type BABEL_CASE_EXPR_TEST_UDT3;
go

-- Mixture of datatypes and numeric without UDT
SELECT CASE 2
   WHEN 1 THEN CAST(123 AS INT)
   WHEN 2 THEN CAST(2.300 AS FLOAT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(54132 AS INT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS NCHAR(100))
   WHEN 2 THEN CAST(3.456 AS FLOAT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(324 AS INT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(5.34 AS FLOAT)
   WHEN 2 THEN CAST(N'登録カード–標準' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(N'登録カード–標準' AS VARCHAR(100))
   WHEN 2 THEN CAST(1321 AS INT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(1235 AS INT)
   WHEN 3 THEN CAST(0.345 AS FLOAT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(346 AS FLOAT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(04545 AS INT)
   WHEN 3 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS VARCHAR(100))
   WHEN 3 THEN CAST(234.234 AS FLOAT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS VARCHAR(100))
   WHEN 2 THEN CAST(3.456 AS FLOAT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(546 AS INT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST(54 AS INT)
   WHEN 3 THEN CAST(0.123 AS FLOAT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN 'abc'
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(6356 AS INT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(234 AS INT)
   WHEN 2 THEN CAST(3456.34 AS FLOAT)
   WHEN 3 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(345.345 AS FLOAT)
   WHEN 2 THEN CAST('char0' AS NCHAR(100))
   WHEN 3 THEN CAST(2354 AS INT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(123 AS INT)
   WHEN 2 THEN CAST(2.300 AS FLOAT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(54132 AS INT)
   WHEN 2 THEN CAST(0 AS BIT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(12.3 AS DECIMAL)
   WHEN 2 THEN CAST(3.456 AS FLOAT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(324 AS INT)
   WHEN 2 THEN CAST(1 AS BIT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(5.34 AS FLOAT)
   WHEN 2 THEN CAST(1.345 AS DECIMAL)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(1 AS BIT)
   WHEN 2 THEN CAST(1321 AS INT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.24 AS DECIMAL)
   WHEN 2 THEN CAST(0 AS BIT)
   WHEN 3 THEN CAST(1.234 AS DECIMAL)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.24 AS DECIMAL)
   WHEN 2 THEN CAST(1235 AS INT)
   WHEN 3 THEN CAST(0.345 AS FLOAT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.24 AS DECIMAL)
   WHEN 2 THEN CAST(234.234 AS DECIMAL)
   WHEN 3 THEN CAST(346 AS FLOAT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.24 AS DECIMAL)
   WHEN 2 THEN CAST(04545 AS INT)
   WHEN 3 THEN CAST(12.4 AS DECIMAL)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.24 AS DECIMAL)
   WHEN 2 THEN CAST(1 AS BIT)
   WHEN 3 THEN CAST(234.234 AS FLOAT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(0 AS BIT)
   WHEN 2 THEN CAST(3.456 AS FLOAT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 2 THEN CAST(123.3 AS DECIMAL)
   WHEN 3 THEN CAST(546 AS INT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 2 THEN CAST(54 AS INT)
   WHEN 3 THEN CAST(0.123 AS FLOAT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 2 THEN CAST(23 AS DECIMAL)
   WHEN 3 THEN CAST(6356 AS INT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(234 AS INT)
   WHEN 2 THEN CAST(3456.34 AS FLOAT)
   WHEN 3 THEN CAST(0 AS BIT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST(345.345 AS FLOAT)
   WHEN 2 THEN CAST(23.12 AS DECIMAL)
   WHEN 3 THEN CAST(2354 AS INT)
END AS RESULT
GO

-- UDT on varchar(max)
create type BABEL_CASE_EXPR_TEST_UDT from varchar(max);
go

SELECT CASE 1
   WHEN 1 THEN CAST('abc' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'a'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('abc' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'a'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('abc' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'a'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(1))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(1))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(1))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('abc' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'a'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(1))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(1))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(1))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT;
go

-- UDT on nvarchar(max)
create type BABEL_CASE_EXPR_TEST_UDT from nvarchar(max);
go

SELECT CASE 1
   WHEN 1 THEN CAST('abc' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'a'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('abc' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'a'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('abc' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'a'
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(1))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(1))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(1))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('abc' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN 'a'
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS VARCHAR(1))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS CHAR(1))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NCHAR(1))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('char0' AS BABEL_CASE_EXPR_TEST_UDT)
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

drop type BABEL_CASE_EXPR_TEST_UDT;
go

-- With max typmod
SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('char1' AS VARCHAR(MAX))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('char1' AS CHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('char1' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('char1' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('char0' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('char1' AS NCHAR(100))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NCHAR(1))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS CHAR(1))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NCHAR(1))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS CHAR(1))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NCHAR(1))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS CHAR(1))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NCHAR(1))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS CHAR(1))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NTEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS TEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NTEXT)
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS TEXT)
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NCHAR(10000))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS CHAR(10000))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NCHAR(10000))
END AS RESULT
GO

SELECT CASE 1
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS CHAR(10000))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NCHAR(10000))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS VARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS CHAR(10000))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS NCHAR(10000))
END AS RESULT
GO

SELECT CASE 2
   WHEN 1 THEN CAST('ASDGASDKGJNASDLIUFAISDUFB' AS NVARCHAR(MAX))
   WHEN 2 THEN CAST('NCHAR' AS CHAR(10000))
END AS RESULT
GO

-- Testing for numeric and decimal
-- Test Case 1: Basic CASE with 6 columns and ELSE
SELECT CASE 3
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
   ELSE 0
END AS RESULT 
FROM BABEL_5341_T1;
GO

-- Test Case 2: CASE with 5 columns and ELSE
SELECT CASE 6
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   ELSE COL6
END AS RESULT 
FROM BABEL_5341_T1;
GO

-- Test Case 3: CASE with 4 columns and ELSE
SELECT CASE 5
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   ELSE COL5
END AS RESULT 
FROM BABEL_5341_T1;
GO

-- Test Case 4: CASE with 3 columns and ELSE
SELECT CASE 4
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   ELSE COL4
END AS RESULT 
FROM BABEL_5341_T1;
GO

-- Test Case 5: CASE with 2 columns and ELSE
SELECT CASE 3
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   ELSE COL3
END AS RESULT 
FROM BABEL_5341_T1;
GO

-- Test Case 6: CASE with 1 column and ELSE
SELECT CASE 2
   WHEN 1 THEN COL1 
   ELSE COL2
END AS RESULT 
FROM BABEL_5341_T1;
GO

-- Test Case 7: CASE with all columns returning a constant value
SELECT CASE 7
   WHEN 1 THEN COL1 
   WHEN 2 THEN COL2
   WHEN 3 THEN COL3
   WHEN 4 THEN COL4
   WHEN 5 THEN COL5
   WHEN 6 THEN COL6
   ELSE 999.99
END AS RESULT 
FROM BABEL_5341_T1;
GO

-- Test Case 8: CASE with mixed constant and column values
SELECT CASE 4
   WHEN 1 THEN 100 
   WHEN 2 THEN COL2
   WHEN 3 THEN 300
   WHEN 4 THEN COL4
   WHEN 5 THEN 500
   ELSE COL6
END AS RESULT 
FROM BABEL_5341_T1;
GO

-- Test Case 9: CASE with views
SELECT * FROM BABEL_5341_V1;
GO

SELECT * FROM BABEL_5341_V2;
GO

SELECT * FROM BABEL_5341_V3;
GO

SELECT * FROM BABEL_5341_V4;
GO

SELECT * FROM BABEL_5341_V5;
GO

SELECT * FROM BABEL_5341_V6;
GO

-- Test Case 10: Using the function
SELECT BABEL_5341_F1(100.00);
GO

SELECT BABEL_5341_F1(200.00);
GO

SELECT BABEL_5341_F1(300.00);
GO

SELECT BABEL_5341_F1(400.00);
GO

-- Test Case 11: Basic DECIMAL and NUMERIC usage
SELECT CASE 3
   WHEN 1 THEN CAST(12345.6789 AS DECIMAL(10,4))
   WHEN 2 THEN CAST(98765.4321 AS NUMERIC(10,4))
   WHEN 3 THEN CAST(1234567.89 AS DECIMAL(12,2))
   WHEN 4 THEN CAST(9.87654321 AS NUMERIC(9,8))
   ELSE CAST(0 AS DECIMAL(5,2))
END AS RESULT
GO

-- Test Case 12: Different scales within the same precision
SELECT CASE 2
   WHEN 1 THEN CAST(12345.6789 AS DECIMAL(10,4))
   WHEN 2 THEN CAST(98765.43 AS DECIMAL(10,2))
   WHEN 3 THEN CAST(123456.7 AS DECIMAL(10,1))
   WHEN 4 THEN CAST(1234567 AS DECIMAL(10,0))
   ELSE CAST(0 AS DECIMAL(10,4))
END AS RESULT
GO

-- Test Case 13: Mixing DECIMAL and NUMERIC with different precisions
SELECT CASE 4
   WHEN 1 THEN CAST(12345.6789 AS DECIMAL(10,4))
   WHEN 2 THEN CAST(98765.4321 AS NUMERIC(12,4))
   WHEN 3 THEN CAST(1234567.89 AS DECIMAL(15,2))
   WHEN 4 THEN CAST(9.87654321 AS NUMERIC(9,8))
   ELSE CAST(0 AS DECIMAL(5,2))
END AS RESULT
GO

-- Test Case 14: Large precisions and scales
SELECT CASE 2
   WHEN 1 THEN CAST(12345678901234567890.1234567890 AS DECIMAL(30,10))
   WHEN 2 THEN CAST(98765432109876543210.9876543210 AS NUMERIC(30,10))
   WHEN 3 THEN CAST(1234567890123456.7890123456 AS DECIMAL(25,10))
   WHEN 4 THEN CAST(9.8765432109876543210 AS NUMERIC(20,19))
   ELSE CAST(0 AS DECIMAL(30,10))
END AS RESULT
GO

-- Test Case 15: Small fractional parts
SELECT CASE 3
   WHEN 1 THEN CAST(12345.000001 AS DECIMAL(12,6))
   WHEN 2 THEN CAST(98765.0000001 AS NUMERIC(14,7))
   WHEN 3 THEN CAST(1234567.0000000001 AS DECIMAL(18,10))
   WHEN 4 THEN CAST(9.000000000000001 AS NUMERIC(17,15))
   ELSE CAST(0.00000001 AS DECIMAL(10,8))
END AS RESULT
GO

-- Test Case 16: Negative numbers
SELECT CASE 2
   WHEN 1 THEN CAST(-12345.6789 AS DECIMAL(10,4))
   WHEN 2 THEN CAST(-98765.4321 AS NUMERIC(10,4))
   WHEN 3 THEN CAST(-1234567.89 AS DECIMAL(12,2))
   WHEN 4 THEN CAST(-9.87654321 AS NUMERIC(9,8))
   ELSE CAST(-0.01 AS DECIMAL(5,2))
END AS RESULT
GO

-- Test Case 17: Potential overflow scenarios
SELECT CASE 3
   WHEN 1 THEN CAST(99999.9999 AS DECIMAL(9,4))
   WHEN 2 THEN CAST(999999.999 AS NUMERIC(9,3))
   WHEN 3 THEN CAST(9999999.99 AS DECIMAL(9,2))
   WHEN 4 THEN CAST(99999999.9 AS NUMERIC(9,1))
   ELSE CAST(0 AS DECIMAL(9,4))
END AS RESULT
GO

-- Test Case 18: Mixing with other numeric types
SELECT CASE 4
   WHEN 1 THEN CAST(12345.6789 AS DECIMAL(10,4))
   WHEN 2 THEN CAST(98765 AS INT)
   WHEN 3 THEN CAST(1234567.89 AS FLOAT)
   WHEN 4 THEN CAST(9 AS BIGINT)
   ELSE CAST(0 AS NUMERIC(5,2))
END AS RESULT
GO

-- Test Case 19: NUMERIC, DATETIME, and SQL_VARIANT in different branches
DECLARE @var SQL_VARIANT
SET @var = CAST(12345.6789 AS NUMERIC(10,4))

SELECT CASE 
    WHEN CAST('2023-05-15' AS DATETIME) > '2023-01-01' THEN CAST(98765.4321 AS NUMERIC(10,4))
    WHEN @var > 10000 THEN CAST('2023-12-31' AS DATETIME)
    WHEN YEAR(GETDATE()) = 2023 THEN @var
    ELSE CAST(11111.1111 AS NUMERIC(10,4))
END AS RESULT
GO

-- Test Case 20: NUMERIC with different precisions, DATETIME, and SQL_VARIANT
DECLARE @var SQL_VARIANT
SET @var = CAST(123456.789 AS NUMERIC(15,3))

SELECT CASE 
    WHEN CAST(12345.6789 AS NUMERIC(10,4)) > 10000 THEN CAST(9876543.21 AS NUMERIC(15,2))
    WHEN CAST('2023-05-15' AS DATETIME) < GETDATE() THEN CAST(123.456789 AS NUMERIC(9,6))
    WHEN SQL_VARIANT_PROPERTY(@var, 'Scale') > 2 THEN CAST(GETDATE() AS DATETIME)
    ELSE @var
END AS RESULT
GO

-- Test Case 21: SQL_VARIANT from BIGINT
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(9223372036854775807 AS BIGINT) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 22: SQL_VARIANT from DECIMAL
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(123.456 AS DECIMAL(10,3)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 23: SQL_VARIANT from FLOAT
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(3.14159265359 AS FLOAT) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 24: SQL_VARIANT from CHAR
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST('A' AS CHAR(1)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 25: SQL_VARIANT from VARCHAR
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST('Hello, World!' AS VARCHAR(50)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 26: SQL_VARIANT from NVARCHAR
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(N'こんにちは' AS NVARCHAR(50)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 27: SQL_VARIANT from DATE
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST('2023-05-15' AS DATE) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 28: SQL_VARIANT from TIME
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST('14:30:00' AS TIME) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 29: SQL_VARIANT from DATETIME2
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST('2023-05-15 14:30:00.1234567' AS DATETIME2(7)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 30: SQL_VARIANT from DATETIMEOFFSET
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST('2023-05-15 14:30:00 +01:00' AS DATETIMEOFFSET) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 31: SQL_VARIANT from BIT
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(1 AS BIT) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 32: SQL_VARIANT from UNIQUEIDENTIFIER
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(NEWID() AS UNIQUEIDENTIFIER) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 33: SQL_VARIANT from VARBINARY
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(0x1234567890 AS VARBINARY(10)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 34: SQL_VARIANT from NUMERIC(10,2)
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(1234567.89 AS NUMERIC(10,2)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 35: SQL_VARIANT from NUMERIC(5,4)
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(0.1234 AS NUMERIC(5,4)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 36: SQL_VARIANT from NUMERIC(20,10)
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(1234567890.1234567890 AS NUMERIC(20,10)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 37: SQL_VARIANT from NUMERIC(38,0) (maximum precision, no decimal places)
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(12345678901234567890123456789012345678 AS NUMERIC(38,0)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 38: SQL_VARIANT from NUMERIC(38,38) (maximum precision and scale)
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(0.12345678901234567890123456789012345678 AS NUMERIC(38,38)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 39: SQL_VARIANT from NUMERIC(1,0) (minimum precision)
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(9 AS NUMERIC(1,0)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 40: SQL_VARIANT from negative NUMERIC
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(CAST(-9876.54321 AS NUMERIC(10,5)) AS SQL_VARIANT)
END AS Result
GO

-- Test Case 41: Numeric branch with time
select case 1
   when 1 then cast(1.23 as numeric(20,2))
   when 2 then cast(1900-01-01 as datetime)
END
go

SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST('1900-01-01' AS DATE)
END AS Result
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST('12:34:56' AS TIME)
END AS Result
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST('1900-01-01 12:34:56.1234567' AS DATETIME2(7))
END AS Result
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST('1900-01-01 12:34:56 +01:00' AS DATETIMEOFFSET)
END AS Result
GO

SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST('1900-01-01 12:34:00' AS SMALLDATETIME)
END AS Result
GO

SELECT CASE 2
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST('1900-01-01' AS DATE)
   WHEN 3 THEN CAST('12:34:56' AS TIME)
   WHEN 4 THEN CAST('1900-01-01 12:34:56.1234567' AS DATETIME2(7))
   WHEN 5 THEN CAST('1900-01-01 12:34:56 +01:00' AS DATETIMEOFFSET)
   WHEN 6 THEN CAST('1900-01-01 12:34:00' AS SMALLDATETIME)
END AS Result
GO

-- Test Case 42: NUMERIC and TINYINT
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(255 AS TINYINT)
END AS Result
GO

-- Test Case 43: NUMERIC and REAL
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(3.14 AS REAL)
END AS Result
GO

-- Test Case 44: NUMERIC and NCHAR
SELECT CASE 1
   WHEN 1 THEN CAST(1.23 AS NUMERIC(20,2))
   WHEN 2 THEN CAST(N'A' AS NCHAR(1))
END AS Result
GO

-- Create UDTs
CREATE TYPE NumericType_BABEL_5341 FROM NUMERIC(20,2);
GO

CREATE TYPE DecimalType_BABEL_5341 FROM DECIMAL(18,4);
GO

CREATE TYPE BigNumericType_BABEL_5341 FROM NUMERIC(38,10);
GO

CREATE TYPE SmallDecimalType_BABEL_5341 FROM DECIMAL(5,2);
GO

-- Test Case 45: Basic CASE with all UDTs
SELECT CASE 4
   WHEN 1 THEN CAST(12345.6789 AS NumericType_BABEL_5341)
   WHEN 2 THEN CAST(98765.4321 AS DecimalType_BABEL_5341)
   WHEN 3 THEN CAST(1234567.8901234567890 AS BigNumericType_BABEL_5341)
   WHEN 4 THEN CAST(99.99 AS SmallDecimalType_BABEL_5341)
   ELSE CAST(0 AS NumericType_BABEL_5341)
END AS RESULT
GO

-- Test Case 46: CASE with UDTs and different precisions
SELECT CASE 3
   WHEN 1 THEN CAST(12345.6789 AS NumericType_BABEL_5341)
   WHEN 2 THEN CAST(98765.4321 AS DecimalType_BABEL_5341)
   WHEN 3 THEN CAST(1234567890123456.7890123456 AS BigNumericType_BABEL_5341)
   WHEN 4 THEN CAST(99.99 AS SmallDecimalType_BABEL_5341)
   ELSE CAST(0 AS DecimalType_BABEL_5341)
END AS RESULT
GO

-- Test Case 47: CASE with UDTs and mathematical operations
SELECT CASE 2
   WHEN 1 THEN CAST(12345.6789 * 2 AS NumericType_BABEL_5341)
   WHEN 2 THEN CAST(98765.4321 / 2 AS DecimalType_BABEL_5341)
   WHEN 3 THEN CAST(1234567.8901234567890 + 1000 AS BigNumericType_BABEL_5341)
   WHEN 4 THEN CAST(99.99 - 50 AS SmallDecimalType_BABEL_5341)
   ELSE CAST(0 AS BigNumericType_BABEL_5341)
END AS RESULT
GO

-- Test Case 48: CASE with UDTs and rounding
SELECT CASE 1
   WHEN 1 THEN CAST(ROUND(12345.6789, 2) AS NumericType_BABEL_5341)
   WHEN 2 THEN CAST(ROUND(98765.4321, 4) AS DecimalType_BABEL_5341)
   WHEN 3 THEN CAST(ROUND(1234567.8901234567890, 10) AS BigNumericType_BABEL_5341)
   WHEN 4 THEN CAST(ROUND(99.99, 1) AS SmallDecimalType_BABEL_5341)
   ELSE CAST(0 AS SmallDecimalType_BABEL_5341)
END AS RESULT
GO

-- Test Case 49: CASE with UDTs and type conversion
SELECT CASE 4
   WHEN 1 THEN CAST(CAST(12345.6789 AS NumericType_BABEL_5341) AS BigNumericType_BABEL_5341)
   WHEN 2 THEN CAST(CAST(98765.4321 AS DecimalType_BABEL_5341) AS SmallDecimalType_BABEL_5341)
   WHEN 3 THEN CAST(CAST(1234567.8901234567890 AS BigNumericType_BABEL_5341) AS NumericType_BABEL_5341)
   WHEN 4 THEN CAST(CAST(99.99 AS SmallDecimalType_BABEL_5341) AS DecimalType_BABEL_5341)
   ELSE CAST(0 AS NumericType_BABEL_5341)
END AS RESULT
GO

-- Test Case 50: CASE with UDTs and potential overflow
SELECT CASE 3
   WHEN 1 THEN CAST(9999999999999999.99 AS NumericType_BABEL_5341)
   WHEN 2 THEN CAST(99999999999999.9999 AS DecimalType_BABEL_5341)
   WHEN 3 THEN CAST(12345678901234567890.1234567890 AS BigNumericType_BABEL_5341)
   WHEN 4 THEN CAST(999.99 AS SmallDecimalType_BABEL_5341)
   ELSE CAST(0 AS BigNumericType_BABEL_5341)
END AS RESULT
GO

-- Test Case 51: CASE with UDTs and aggregate functions
SELECT CASE 2
   WHEN 1 THEN CAST(AVG(CAST(COLUMN_VALUE AS NumericType_BABEL_5341)) AS NumericType_BABEL_5341)
   WHEN 2 THEN CAST(SUM(CAST(COLUMN_VALUE AS DecimalType_BABEL_5341)) AS DecimalType_BABEL_5341)
   WHEN 3 THEN CAST(MAX(CAST(COLUMN_VALUE AS BigNumericType_BABEL_5341)) AS BigNumericType_BABEL_5341)
   WHEN 4 THEN CAST(MIN(CAST(COLUMN_VALUE AS SmallDecimalType_BABEL_5341)) AS SmallDecimalType_BABEL_5341)
   ELSE CAST(0 AS NumericType_BABEL_5341)
END AS RESULT
FROM (VALUES (100), (200), (300)) AS T(COLUMN_VALUE)
GO

-- Test Case 52: UDTs with INT and BIGINT
SELECT CASE 3
   WHEN 1 THEN CAST(12345 AS NumericType_BABEL_5341)
   WHEN 2 THEN CAST(9876543210 AS BigNumericType_BABEL_5341)
   WHEN 3 THEN CAST(1000 AS INT)
   WHEN 4 THEN CAST(9223372036854775807 AS BIGINT)
   ELSE CAST(0 AS SmallDecimalType_BABEL_5341)
END AS RESULT
GO

-- Test Case 53: UDTs with FLOAT and REAL
SELECT CASE 2
   WHEN 1 THEN CAST(123.45 AS DecimalType_BABEL_5341)
   WHEN 2 THEN CAST(98765.4321 AS FLOAT)
   WHEN 3 THEN CAST(1234.56 AS REAL)
   WHEN 4 THEN CAST(9.87654321 AS NumericType_BABEL_5341)
   ELSE CAST(0 AS BigNumericType_BABEL_5341)
END AS RESULT
GO

-- Test Case 54: UDTs with MONEY and SMALLMONEY
SELECT CASE 4
   WHEN 1 THEN CAST(12345.67 AS MONEY)
   WHEN 2 THEN CAST(98.76 AS SMALLMONEY)
   WHEN 3 THEN CAST(1234.5678 AS DecimalType_BABEL_5341)
   WHEN 4 THEN CAST(9876.54 AS NumericType_BABEL_5341)
   ELSE CAST(0 AS SmallDecimalType_BABEL_5341)
END AS RESULT
GO

-- Test Case 55: UDTs with VARCHAR and NVARCHAR
SELECT CASE 3
   WHEN 1 THEN CAST(CAST('12345.67' AS VARCHAR(20)) AS NumericType_BABEL_5341)
   WHEN 2 THEN CAST(CAST(N'98765.4321' AS NVARCHAR(20)) AS DecimalType_BABEL_5341)
   WHEN 3 THEN CAST('1234567.8901' AS BigNumericType_BABEL_5341)
   WHEN 4 THEN CAST(N'99.99' AS SmallDecimalType_BABEL_5341)
   ELSE CAST(0 AS NumericType_BABEL_5341)
END AS RESULT
GO

-- Test Case 56: UDTs with BIT and mathematical operations
SELECT CASE 3
   WHEN 1 THEN CAST(1 AS BIT) * CAST(12345.67 AS NumericType_BABEL_5341)
   WHEN 2 THEN CAST(1 AS BIT) * CAST(98765.4321 AS DecimalType_BABEL_5341)
   WHEN 3 THEN CAST(1 AS BIT) + CAST(1234567.8901 AS BigNumericType_BABEL_5341)
   WHEN 4 THEN CAST(1 AS BIT) - CAST(99.99 AS SmallDecimalType_BABEL_5341)
   ELSE CAST(0 AS NumericType_BABEL_5341)
END AS RESULT
GO

DROP TYPE NumericType_BABEL_5341;
GO

DROP TYPE DecimalType_BABEL_5341;
GO

DROP TYPE BigNumericType_BABEL_5341;
GO

DROP TYPE SmallDecimalType_BABEL_5341;
GO

-- test cases
-- Test Case 57: Basic DECIMAL and NUMERIC mix
SELECT * FROM (VALUES 
    (CAST(1.1 AS DECIMAL(3,1))),
    (CAST(2.2 AS NUMERIC(3,1))),
    (CAST(3.3 AS DECIMAL(3,1)))
) AS "VALUES";
GO

-- Test Case 58: Different precisions and scales
SELECT * FROM (VALUES 
    (CAST(1.23456 AS DECIMAL(6,5))),
    (CAST(23.4567 AS NUMERIC(6,4))),
    (CAST(345.678 AS DECIMAL(6,3))),
    (CAST(4567.89 AS NUMERIC(6,2)))
) AS "VALUES";
GO

-- Test Case 59: Large precisions
SELECT * FROM (VALUES 
    (CAST(1234567890123456789.1234567890 AS DECIMAL(38,10))),
    (CAST(9876543210987654321.0987654321 AS NUMERIC(38,10))),
    (CAST(1111111111111111111.1111111111 AS DECIMAL(38,10)))
) AS "VALUES";
GO

-- Test Case 60: Small scales
SELECT * FROM (VALUES 
    (CAST(1.1 AS DECIMAL(38,1))),
    (CAST(22.22 AS NUMERIC(38,2))),
    (CAST(333.333 AS DECIMAL(38,3))),
    (CAST(4444.4444 AS NUMERIC(38,4)))
) AS "VALUES";
GO

-- Test Case 61: Mix of positive and negative numbers
SELECT * FROM (VALUES 
    (CAST(-1.23 AS DECIMAL(5,2))),
    (CAST(4.56 AS NUMERIC(5,2))),
    (CAST(-7.89 AS DECIMAL(5,2))),
    (CAST(0.12 AS NUMERIC(5,2)))
) AS "VALUES";
GO

-- Test Case 62: Very small numbers
SELECT * FROM (VALUES 
    (CAST(0.000000000123 AS DECIMAL(15,12))),
    (CAST(0.000000000456 AS NUMERIC(15,12))),
    (CAST(0.000000000789 AS DECIMAL(15,12)))
) AS "VALUES";
GO

-- Test Case 63: Very large numbers
SELECT * FROM (VALUES 
    (CAST(123456789012345678901234567890.12 AS DECIMAL(38,2))),
    (CAST(987654321098765432109876543210.98 AS NUMERIC(38,2))),
    (CAST(111111111111111111111111111111.11 AS DECIMAL(38,2)))
) AS "VALUES";
GO

-- Test Case 64: Mix of integer and fractional parts
SELECT * FROM (VALUES 
    (CAST(1 AS DECIMAL(38,0))),
    (CAST(2.2 AS NUMERIC(38,1))),
    (CAST(3.33 AS DECIMAL(38,2))),
    (CAST(4.444 AS NUMERIC(38,3)))
) AS "VALUES";
GO

-- Test Case 65: Edge cases
SELECT * FROM (VALUES 
    (CAST(0.9999999999999999999999999999999999999 AS DECIMAL(38,37))),
    (CAST(9.999999999999999999999999999999999999 AS NUMERIC(38,36))),
    (CAST(0.0000000000000000000000000000000000001 AS DECIMAL(38,37)))
) AS "VALUES";
GO

-- Test Case 66: Mix of DECIMAL and NUMERIC with different precisions
SELECT * FROM (VALUES 
    (CAST(1.1 AS DECIMAL(5,1))),
    (CAST(2.22 AS NUMERIC(10,2))),
    (CAST(3.333 AS DECIMAL(15,3))),
    (CAST(4.4444 AS NUMERIC(20,4)))
) AS "VALUES";
GO

-- Test Case 67: Mix of numeric, decimal, integer, and varchar
SELECT * FROM (VALUES 
    (CAST(1.1 AS DECIMAL(3,1)), 10, 'ABC'),
    (CAST(2.2 AS NUMERIC(3,1)), 20, 'DEF'),
    (CAST(3.3 AS DECIMAL(3,1)), 30, 'GHI')
) AS "VALUES" (dec_num, int_num, str_val);
GO

-- Test Case 68: Mix with date, time, and boolean
SELECT * FROM (VALUES 
    (CAST(1.23 AS DECIMAL(4,2)), CAST('2023-01-01' AS DATE), CAST('10:30:00' AS TIME), TRUE),
    (CAST(4.56 AS NUMERIC(4,2)), CAST('2023-02-15' AS DATE), CAST('14:45:00' AS TIME), FALSE),
    (CAST(7.89 AS DECIMAL(4,2)), CAST('2023-03-30' AS DATE), CAST('20:15:00' AS TIME), TRUE)
) AS "VALUES" (num_val, date_val, time_val, bool_val);
GO

-- Test Case 69: Mix with timestamp and interval
SELECT * FROM (VALUES 
    (CAST(123.45 AS DECIMAL(5,2)), CAST('2023-01-01 12:00:00' AS TIMESTAMP), CAST('1 day' AS INTERVAL)),
    (CAST(678.90 AS NUMERIC(5,2)), CAST('2023-06-15 18:30:00' AS TIMESTAMP), CAST('2 hours' AS INTERVAL)),
    (CAST(246.80 AS DECIMAL(5,2)), CAST('2023-12-31 23:59:59' AS TIMESTAMP), CAST('30 minutes' AS INTERVAL))
) AS "VALUES" (num_val, ts_val, interval_val);
GO

-- Test Case 70: Mix with char, varchar, and text
SELECT * FROM (VALUES 
    (CAST(1.1 AS DECIMAL(3,1)), CAST('A' AS CHAR(1)), CAST('ABC' AS VARCHAR(10)), 'This is a text'),
    (CAST(2.2 AS NUMERIC(3,1)), CAST('B' AS CHAR(1)), CAST('DEF' AS VARCHAR(10)), 'Another text'),
    (CAST(3.3 AS DECIMAL(3,1)), CAST('C' AS CHAR(1)), CAST('GHI' AS VARCHAR(10)), 'Yet another text')
) AS "VALUES" (num_val, char_val, varchar_val, text_val);
GO

-- Test Case 71: Mix with money and bit
SELECT * FROM (VALUES 
    (CAST(1.23 AS DECIMAL(3,2)), CAST(100.00 AS MONEY), CAST('1' AS BIT)),
    (CAST(4.56 AS NUMERIC(3,2)), CAST(200.50 AS MONEY), CAST('0' AS BIT)),
    (CAST(7.89 AS DECIMAL(3,2)), CAST(350.75 AS MONEY), CAST('1' AS BIT))
) AS "VALUES" (num_val, money_val, bit_val);
GO

-- Test Case 72: UNION with DECIMAL and INTEGER
SELECT CAST(1.23 AS DECIMAL(5,2)) AS value
UNION ALL
SELECT 456
ORDER BY value;
GO

-- Test Case 73: UNION with NUMERIC, DECIMAL, and FLOAT
SELECT CAST(1.23456 AS NUMERIC(10,5)) AS value
UNION ALL
SELECT CAST(2.34567 AS DECIMAL(10,5))
UNION ALL
SELECT CAST(3.45678 AS FLOAT)
ORDER BY value;
GO

-- Test Case 74: UNION with different precisions and scales
SELECT CAST(1.23 AS DECIMAL(5,2)) AS value
UNION ALL
SELECT CAST(2.3456 AS NUMERIC(10,4))
UNION ALL
SELECT CAST(3.456789 AS DECIMAL(15,6))
ORDER BY value;
GO

-- Test Case 75: UNION with negative numbers and zero
SELECT CAST(-1.23 AS DECIMAL(5,2)) AS value
UNION ALL
SELECT CAST(0 AS NUMERIC(5,2))
UNION ALL
SELECT CAST(1.23 AS DECIMAL(5,2))
ORDER BY value;
GO

-- Test Case 75: UNION with large numbers
SELECT CAST(1234567890.12345 AS DECIMAL(20,5)) AS value
UNION ALL
SELECT CAST(9876543210.98765 AS NUMERIC(20,5))
UNION ALL
SELECT CAST(1111111111.11111 AS DECIMAL(20,5))
ORDER BY value;
GO

-- Test Case 76: UNION with small numbers
SELECT CAST(0.00000123 AS DECIMAL(10,8)) AS value
UNION ALL
SELECT CAST(0.00000456 AS NUMERIC(10,8))
UNION ALL
SELECT CAST(0.00000789 AS DECIMAL(10,8))
ORDER BY value;
GO

-- Test Case 77: UNION with DECIMAL, NUMERIC, and VARCHAR
SELECT CAST(1.23 AS DECIMAL(5,2)) AS value
UNION ALL
SELECT CAST(4.56 AS NUMERIC(5,2))
UNION ALL
SELECT CAST('7.89' AS VARCHAR(10))
ORDER BY value;
GO

-- Test Case 78: UNION with different integer parts
SELECT CAST(1.23 AS DECIMAL(10,2)) AS value
UNION ALL
SELECT CAST(123.45 AS NUMERIC(10,2))
UNION ALL
SELECT CAST(12345.67 AS DECIMAL(10,2))
ORDER BY value;
GO

-- Test Case 79: UNION with extreme values
SELECT CAST(9999999999.99999999 AS DECIMAL(18,8)) AS value
UNION ALL
SELECT CAST(0.00000001 AS NUMERIC(18,8))
UNION ALL
SELECT CAST(5555555555.55555555 AS DECIMAL(18,8))
ORDER BY value;
GO

-- Test Case 80: UNION with NULL values
SELECT CAST(NULL AS DECIMAL(5,2)) AS value
UNION ALL
SELECT CAST(1.23 AS NUMERIC(5,2))
UNION ALL
SELECT CAST(NULL AS DECIMAL(5,2))
UNION ALL
SELECT CAST(4.56 AS NUMERIC(5,2))
ORDER BY value;
GO

-- Test Case 81: UNION with MONEY type
SELECT CAST(1.23 AS DECIMAL(10,2)) AS value
UNION ALL
SELECT CAST(4.56 AS MONEY)
UNION ALL
SELECT CAST(7.89 AS NUMERIC(10,2))
ORDER BY value;
GO

-- Test Case 82: UNION with SMALLMONEY type
SELECT CAST(1.23 AS DECIMAL(6,2)) AS value
UNION ALL
SELECT CAST(4.56 AS SMALLMONEY)
UNION ALL
SELECT CAST(7.89 AS NUMERIC(6,2))
ORDER BY value;
GO

-- Test Case 83: DECIMAL(38,1) - 37 digits before decimal, 1 after
SELECT CAST(1234567890123456789012345678901234567.8 AS DECIMAL(38,1)) AS value
UNION ALL
SELECT CAST(9999999999999999999999999999999999999.9 AS DECIMAL(38,1))
UNION ALL
SELECT CAST(1000000000000000000000000000000000000.0 AS DECIMAL(38,1))
ORDER BY value;
GO

-- Test Case 84: DECIMAL(38,2) - 36 digits before decimal, 2 after
SELECT CAST(123456789012345678901234567890123456.78 AS DECIMAL(38,2)) AS value
UNION ALL
SELECT CAST(999999999999999999999999999999999999.99 AS DECIMAL(38,2))
UNION ALL
SELECT CAST(100000000000000000000000000000000000.00 AS DECIMAL(38,2))
ORDER BY value;
GO

-- Test Case 85: DECIMAL(38,5) - 33 digits before decimal, 5 after
SELECT CAST(12345678901234567890123456789012.34567 AS DECIMAL(38,5)) AS value
UNION ALL
SELECT CAST(99999999999999999999999999999999.99999 AS DECIMAL(38,5))
UNION ALL
SELECT CAST(10000000000000000000000000000000.00001 AS DECIMAL(38,5))
ORDER BY value;
GO

-- Test Case 86: Mixing different scales with precision 38
SELECT CAST(1234567890123456789012345678901234567.8 AS DECIMAL(38,1)) AS value
UNION ALL
SELECT CAST(123456789012345678901234567890123456.78 AS DECIMAL(38,2))
UNION ALL
SELECT CAST(12345678901234567890123456789012.34567 AS DECIMAL(38,5))
ORDER BY value;
GO

-- Test Case 88: Very small fractional part with precision 38
SELECT CAST(9999999999999999999999999999999999999.1 AS DECIMAL(38,1)) AS value
UNION ALL
SELECT CAST(9999999999999999999999999999999999999.01 AS DECIMAL(38,2))
UNION ALL
SELECT CAST(9999999999999999999999999999999999999.00001 AS DECIMAL(38,5))
ORDER BY value;
GO

-- Test Case 89: Overflow scenarios with precision 38
SELECT CAST(9999999999999999999999999999999999999.9 AS DECIMAL(38,1)) AS value
UNION ALL
SELECT CAST(9999999999999999999999999999999999999.99 AS DECIMAL(38,2))
UNION ALL
SELECT CAST(10000000000000000000000000000000000000.0 AS DECIMAL(38,1))  -- This will cause an overflow
ORDER BY value;
GO

-- Test Case 90: Mixing DECIMAL and NUMERIC with precision 38 and small scales
SELECT CAST(1234567890123456789012345678901234567.8 AS DECIMAL(38,1)) AS value
UNION ALL
SELECT CAST(123456789012345678901234567890123456.78 AS NUMERIC(38,2))
UNION ALL
SELECT CAST(12345678901234567890123456789012.34567 AS DECIMAL(38,5))
ORDER BY value;
GO

-- Test Case 91: NULL values with precision 38 and small scales
SELECT CAST(NULL AS DECIMAL(38,1)) AS value
UNION ALL
SELECT CAST(9999999999999999999999999999999999999.9 AS DECIMAL(38,1))
UNION ALL
SELECT CAST(NULL AS NUMERIC(38,2))
ORDER BY value;
GO

-- Test Case 92: customer query
DECLARE @test_int int = 1;
SELECT a.integer_one, a.integer_two, 
ratio = a.integer_one / CONVERT(DECIMAL, a.integer_two),
ratio_case_one = CASE WHEN a.integer_two = 0 THEN NULL ELSE a.integer_one / CONVERT(DECIMAL, a.integer_two) END,
ratio_case_two = CASE WHEN 1 = 0 THEN NULL ELSE a.integer_one / CONVERT(DECIMAL, a.integer_two) END,
ratio_case_three = CASE WHEN @test_int = 0 THEN NULL ELSE a.integer_one / CONVERT(DECIMAL, a.integer_two) END
FROM BABEL_5341_T2 a;
GO

-- Test Case 93: to get scale and precision of views from system metadata
SELECT 
    o.[name] AS view_name,
    c.[name] AS column_name,
    t.[name] AS data_type,
    c.[precision],
    c.[scale]
FROM 
    sys.views o
    INNER JOIN sys.columns c ON o.[object_id] = c.[object_id]
    INNER JOIN sys.types t ON c.[user_type_id] = t.[user_type_id]
WHERE 
    o.[name] = 'BABEL_5341_V1'
    AND c.[name] = 'RESULT';
GO

SELECT 
    o.[name] AS view_name,
    c.[name] AS column_name,
    t.[name] AS data_type,
    c.[precision],
    c.[scale]
FROM 
    sys.views o
    INNER JOIN sys.columns c ON o.[object_id] = c.[object_id]
    INNER JOIN sys.types t ON c.[user_type_id] = t.[user_type_id]
WHERE 
    o.[name] = 'BABEL_5341_V2'
    AND c.[name] = 'RESULT';
GO

SELECT 
    o.[name] AS view_name,
    c.[name] AS column_name,
    t.[name] AS data_type,
    c.[precision],
    c.[scale]
FROM 
    sys.views o
    INNER JOIN sys.columns c ON o.[object_id] = c.[object_id]
    INNER JOIN sys.types t ON c.[user_type_id] = t.[user_type_id]
WHERE 
    o.[name] = 'BABEL_5341_V3'
    AND c.[name] = 'RESULT';
GO

SELECT 
    o.[name] AS view_name,
    c.[name] AS column_name,
    t.[name] AS data_type,
    c.[precision],
    c.[scale]
FROM 
    sys.views o
    INNER JOIN sys.columns c ON o.[object_id] = c.[object_id]
    INNER JOIN sys.types t ON c.[user_type_id] = t.[user_type_id]
WHERE 
    o.[name] = 'BABEL_5341_V4'
    AND c.[name] = 'RESULT';
GO

SELECT 
    o.[name] AS view_name,
    c.[name] AS column_name,
    t.[name] AS data_type,
    c.[precision],
    c.[scale]
FROM 
    sys.views o
    INNER JOIN sys.columns c ON o.[object_id] = c.[object_id]
    INNER JOIN sys.types t ON c.[user_type_id] = t.[user_type_id]
WHERE 
    o.[name] = 'BABEL_5341_V5'
    AND c.[name] = 'RESULT';
GO

SELECT 
    o.[name] AS view_name,
    c.[name] AS column_name,
    t.[name] AS data_type,
    c.[precision],
    c.[scale]
FROM 
    sys.views o
    INNER JOIN sys.columns c ON o.[object_id] = c.[object_id]
    INNER JOIN sys.types t ON c.[user_type_id] = t.[user_type_id]
WHERE 
    o.[name] = 'BABEL_5341_V6'
    AND c.[name] = 'RESULT';
GO
